package DomainLayer;

import Annotations.AttributeNameAnnotation;
import Annotations.ValueObjectNameAnnotation;


@ValueObjectNameAnnotation(Name="UserInfo")
public class UserInfoValueObject extends AbstractValueObject{
	@AttributeNameAnnotation(Name = "FirstName", isAggregator = false) 
	private final String firstName;
	@AttributeNameAnnotation(Name = "SecondName", isAggregator = false) 
	private final String secondName;
	@AttributeNameAnnotation(Name = "MiddleName", isAggregator = false)
	private final String middleName;
	@AttributeNameAnnotation(Name = "Login", isAggregator = false) 
  	private final String login;
	@AttributeNameAnnotation(Name = "Password", isAggregator = false) 
	private final String password;
	@AttributeNameAnnotation(Name = "Salt", isAggregator = false)
	private final String salt;
	@AttributeNameAnnotation(Name = "Gender", isAggregator = false) 
	private final Gender gender;
	@AttributeNameAnnotation(Name = "Age", isAggregator = false) 
	private final Integer age;

	public UserInfoValueObject() {
		super();
		firstName = null;
		secondName = null;
		middleName = null;
		login = null;
		password = null;
		gender = null;
		age = null;
		salt = null;
	}

	/**
	 * 
	 * @param Current
	 *            State
	 * @param firstName
	 *            , secondName, middleName, login, password, salt, lastIP,
	 *            gender, age
	 */
	public UserInfoValueObject(UserInfoValueObject currentState,
			Object... changes) {
		super(currentState, changes[0]);
		firstName = (changes[1] != null ? ((String) changes[1]).toString()
				: currentState.firstName);
		secondName = (changes[2] != null ? ((String) changes[2]).toString()
				: currentState.secondName);
		middleName = (changes[3] != null ? ((String) changes[3]).toString()
				: currentState.middleName);
		login = (changes[4] != null ? ((String) changes[4]).toString()
				: currentState.login);
		password = (changes[5] != null ? ((String) changes[5]).toString()
				: currentState.password);
		salt = (changes[6] != null ? ((String) changes[6]).toString()
				: currentState.salt);
		gender = (changes[7] != null ? ((Gender) changes[7])
				: currentState.gender);
		age = (changes[8] != null ? ((Integer) changes[8]).intValue()
				: currentState.age);
	}

	public String getFirstName() {
		return firstName;
	}

	public String getSecondName() {
		return secondName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public String getLogin() {
		return login;
	}

	public String getPassword() {
		return password;
	}

	public String getSalt() {
		return salt;
	}

	public Gender getGender() {
		return gender;
	}

	public Integer getAge() {
		return age;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserInfoValueObject other = (UserInfoValueObject) obj;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		return true;
	}
}